package com.api.regression.group.uploadnewdocumentattached;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;
import com.zyncro.api.model.UploadDocumentResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-upload.xml" })
public class UploadNewDocumentAttachedWithoutQuota extends AbstractApiTest {

	@Value("#{group_toUploadQuota[owner].appId}")
	private String userUrn;

	@Value("#{group_toUploadQuota[owner].password}")
	private String userPassword;

	@Value("#{group_toUploadQuota.urn}")
	private String groupUrn;

	@Value("#{group_toUploadQuota.eventUrn}")
	private String eventUrn;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@SuppressWarnings("deprecation")
	@Test(expectedExceptions = ZyncroApiException.class)
	public void testUploadGroup() throws ZyncroApiException, FileNotFoundException {

		File file = new File("FileName.txt");
		String fileName = file.getName();
		Long length = file.length();

		FileInputStream inputStream = new FileInputStream(file);

		String descriptionQuery = "Description";
		String parentDocumentUrn = null;

		ObjectResultApi<UploadDocumentResultApi> result = getApi().getService(IGroupApiService.class).uploadNewDocumentAttached(groupUrn,
				getApi().getAccessKey(), parentDocumentUrn, eventUrn, descriptionQuery, fileName, length, inputStream);
		UploadDocumentResultApi document = result.getObject();

		AssertApi.assertUrnType(document.getDocumentUrn(), UrnType.DOCUMENT);
	}
}
